package pfc.modeloer;

import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.Map;

public abstract class ERRelationShip extends ERElement {

    private String _name;
    private int _grade;
    private LinkedHashSet<EREntity> _members = new LinkedHashSet<EREntity>();
    private LinkedHashSet<ERReference> _referencias = new LinkedHashSet<ERReference>();
    public static enum RelationType {OneToMany, OneToOne,ManyToMany};
    //public static final  String OneToMany = "1-N";
    //public static final  String OneToOne = "1-1";
    //public static final  String ManyToMany = "M-N";

    protected RelationType _typeEnum;
    protected String _type;

    public ERRelationShip() {
    }

    public RelationType getTypeEnum() {
        return _typeEnum;
    }

    public void setTypeEnum(RelationType _type) {
        this._typeEnum = _type;
        this._type = _type.toString();
    }

    public String getType() {
        return _type;
    }

    public void setType(String _type) {
        this._type = _type;
        this._typeEnum = ERRelationShip.RelationType.valueOf(_type);
    }

    




    public int getGrade() {
        return _grade;
    }

    public void setGrade(int _grade) {
        this._grade = _grade;
    }

    public LinkedHashSet<EREntity> getMembers() {
        return _members;
    }

    public void addMember(EREntity member)
    {
        this._members.add(member);
    }
    public void setMembers(LinkedHashSet<EREntity> _members) {
        this._members = _members;
    }

    public String getName() {
        return _name;
    }

    public void setName(String _name) {
        this._name = _name;
    }

    public void addReference(ERReference referencia) {
        _referencias.add(referencia);
    }

    public Collection<ERReference> getReferences()
    {
        return _referencias;
    }

    public String toVerboseString() {
            StringBuffer result = new StringBuffer();

            result.append("Relacion [name=");
            result.append(getName());

            return result.toString();
        }
    
    public class Rol {

        private String _name;
        private String _cardinalidad;

        public Rol(String _name, String _cardinalidad) {
            this._name = _name;
            this._cardinalidad = _cardinalidad;
        }

        public String getCardinalidad() {
            return _cardinalidad;
        }

        public void setCardinalidad(String _cardinalidad) {
            this._cardinalidad = _cardinalidad;
        }

        public String getName() {
            return _name;
        }

        public void setName(String _name) {
            this._name = _name;
        }

        
    }
}
